package com.qing.demo.netty.client;

import com.qing.demo.netty.codec.ObjDecoder;
import com.qing.demo.netty.codec.ObjEncoder;
import com.qing.demo.netty.domain.FileTransferProtocol;
import com.qing.demo.netty.domain.MsgInfo;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.protobuf.ProtobufDecoder;
import io.netty.handler.codec.protobuf.ProtobufEncoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;

/**
 * @author caozhipeng
 * @date 2025/7/25
 *
 * netty通信就向一个流水channel管道，我们可以在管道的中间插入一些‘挡板’为我们服务。
 * 比如字符串的编码解码
 * ChannelInitializer:挡板
 */
public class MyChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {

        socketChannel.pipeline().addLast(new ObjDecoder(FileTransferProtocol.class));
        socketChannel.pipeline().addLast(new ObjEncoder(FileTransferProtocol.class));

        socketChannel.pipeline().addLast(new MyClientHandler());
    }
}
